package com.aluka.nirvana.framework.security.handler;


import com.aluka.nirvana.framework.security.utils.ResponseUtils;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 自定义 Security 注销成功处理类
 * @author gongli
 * @since 2019/4/10 13:40
 */
@Component
public class CustomLogoutSuccessHandler implements LogoutSuccessHandler {

    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest,
                                HttpServletResponse httpServletResponse,
                                Authentication authentication) throws IOException, ServletException {
        SecurityContextHolder.clearContext();
        ResponseUtils.writeResponse(httpServletResponse, HttpStatus.OK,"注销成功!");
    }
}
